package com.opennetexam.manager.controller;

import com.opennetexam.manager.bussinessservice.WANExamBusinessService;
import com.opennetexam.manager.common.CommonFunction;
import com.opennetexam.manager.dto.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description 网络考试
 * @Author 奶茶
 * Created by on 2018/11/4 10:20.
 */
@Controller
@RequestMapping(value = "/Examiner")
public class WANExaminerController {

    @Autowired
    private WANExamBusinessService wanExamBusinessService;

    /**
     * 网考登录
     * @param examCardNo
     * @param password
     * @return
     */
    @RequestMapping(value = "/Login",method = RequestMethod.POST)
    public @ResponseBody LoginVo login(String examCardNo,String password){
        //去空
        examCardNo = examCardNo.trim();
        return wanExamBusinessService.examinerLoginBussines(examCardNo,password);
    }

    /**
     * 获取考生科目列表
     * @param token
     * @param response
     */
    @RequestMapping(value = "/GetSubjectList",method = RequestMethod.GET)
    public void getSubjectList(String token, HttpServletResponse response){
        CommonFunction.responseWrite(response, wanExamBusinessService.getSubjectList(token));
    }

    /**
     * 获取考生考试信息(考生是否可以考试)
     * @param token
     * @param subjectID
     */
    @RequestMapping(value = "/GetExamInfo",method = RequestMethod.POST)
    public void getExamInfo(String token,String subjectID,HttpServletResponse response){
        CommonFunction.responseWrite(response, wanExamBusinessService.getExamInfo(token,subjectID));
    }

    /**
     * 试卷下载页跳转
     * @param token
     */
    @RequestMapping(value = "/DownloadPaper",method = RequestMethod.GET)
    public String downLoadPaper(String token, Model model){
        model.addAttribute("token",token);
        model.addAttribute("loginMode", wanExamBusinessService.getLoginMode(token));
        return "examinee/DownloadPaper";
    }

    /**
     * 试卷下载页获取考生信息
     * @param token
     * @param response
     */
    @RequestMapping(value = "/GetExaminerInfoForDownLoadPaper",method = RequestMethod.GET)
    public void getExaminerInfoForDownLoadPaper(String token,HttpServletResponse response){
        CommonFunction.responseWrite(response, wanExamBusinessService.getExaminerInfoFromCache(token));
    }

}
